package com.uxwine.cmm;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class UxAdapter<E> extends BaseAdapter
{
	protected List<E> mData;
	
	@Override
	public int getCount()
	{
		return (null == mData) ? 0 : mData.size();
	}

	@Override
	public Object getItem(int position)
	{
		return (null == mData) ? null : mData.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}
	
	public List<E> getData()
	{
		return mData;
	}
	
	public void add(E item, boolean bNotify)
	{
		synchronized (mData)
		{
			mData.add(item);
			if(bNotify)
				notifyDataSetChanged();			
		}
	}
	
	public void remove(E item, boolean bNotify)
	{
		synchronized (mData)
		{
			mData.remove(item);
			if(bNotify)
				notifyDataSetChanged();	
		}
	}
	
	public void remove(int location, boolean bNotify)
	{
		synchronized (mData)
		{
			mData.remove(location);
			if(bNotify)
				notifyDataSetChanged();	
		}
	}
	
	public void clear()
	{
		synchronized (mData)
		{
			mData.clear();
		}
	}
}
